import axios from 'axios'
import qs from 'querystring'
import { successCode } from 'constants/ajaxStatusCode'
const get = async function(url, data) {
    try {
        let res = await axios.get(url, {params: data})
        res = res.data
        return new Promise((resolve, reject) => {
            if (res.code === successCode) {
                resolve(res)
            } else {
                reject(res)
            }
        })
    } catch(err) {
        alert('服务器出错')
        console.log(err)
    }
}
const post = async function(url, data) {
    try {
        let res = await axios.post(url, qs.stringify(data))
        res = res.data
        return new Promise((resolve, reject) => {
            if (res.code === successCode) {
                resolve(res)
            } else {
                reject(res)
            }
        })
    } catch(err) {
        alert('服务器出错')
        console.log(err)
    }
}
export { get, post}